<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
	<head lang="en">
		<meta charset="utf-8" />
		<title>order</title>
		<link rel="stylesheet" type="text/css" href="css/public.css"/>
		<link rel="stylesheet" type="text/css" href="css/proList.css" />
		<link rel="stylesheet" type="text/css" href="css/mygxin.css" />
	</head>
	<body>
		<jsp:include page="header.jsp"></jsp:include>
		<!----------------------------------------order------------------>
		<div class="order cart mt">
			<!-----------------site------------------->
			<div class="site">
				<p class="wrapper clearfix">
					<span class="fl">订单确认</span>
				</p>
			</div>
			<!-----------------orderCon------------------->
			<div class="orderCon wrapper clearfix">
				<div class="orderL fl">
					<!--------h3---------------->
					<h3>收件信息<a href="javascript:editAdd();" class="fr">新增地址</a></h3>
					<!--------addres---------------->
					<div class="addres clearfix">
					<c:choose>
				        <c:when test="${empty address }"></c:when>
				        <c:otherwise>
				            <c:forEach items="${address }" var="a">
				            	<c:choose>
				            		<c:when test="${a.defaultAddress eq 1 }">
				            			<div class="addre fl on" addressId="${a.id }" divFlag="address">
											<div class="tit clearfix">
												<p class="fl">${a.name }
													<span class="default">[默认地址]</span>
												</p>
												<p class="fr">
													<a href="javascript:deleteAddress('${a.id}');">删除</a>
													<span>|</span>
													<a href="javascript:editUp('${a.id}','${a.name}','${a.phone}','${a.addressInfo}');" class="edit">编辑</a>
												</p>
											</div>
											<div class="addCon">
												<p>${a.province }&nbsp;${a.city }&nbsp;${a.area }&nbsp;${a.addressInfo }</p>
												<p>${a.phone }</p>
											</div>
										</div>
				            		</c:when>
				            		<c:otherwise>
				            			<div class="addre fl" addressId="${a.id }" divFlag="address">
											<div class="tit clearfix">
												<p class="fl">${a.name }
													<span class="default">[设为默认地址]</span>
												</p>
												<p class="fr">
													<a href="javascript:deleteAddress('${a.id}');">删除</a>
													<span>|</span>
													<a href="javascript:editUp('${a.id}','${a.name}','${a.phone}','${a.addressInfo}');">编辑</a>
												</p>
											</div>
											<div class="addCon">
												<p>${a.province }&nbsp;${a.city }&nbsp;${a.area }&nbsp;${a.addressInfo }</p>
												<p>${a.phone }</p>
											</div>
										</div>
				            		</c:otherwise>
				            	</c:choose>
				            </c:forEach>
				        </c:otherwise>
			        </c:choose>
					</div>
					<h3>支付方式</h3>
					<!--------way---------------->
					<div class="way clearfix">
						<img class="on" src="images/way01.jpg"> 
					</div>
					<!--<h3>订单备注</h3>
					------dis--------------
					<div class="dis clearfix">
						<span class="on">顺风快递</span>
						<span>百世汇通</span>
						<span>圆通快递</span>
						<span>中通快递</span>
					</div>-->
				</div>
				<div class="orderR fr">
					<div class="msg">
						<h3>订单内容<a href="findShopcart.do" class="fr">返回购物车</a></h3>
						<!--------ul---------------->
						<c:choose>
					        <c:when test="${empty shopcart }"></c:when>
					        <c:otherwise>
					            <c:forEach items="${shopcart }" var="s">
									<ul class="clearfix">
										<li class="fl">
											<img src="${s.pimg }" width="100px" height="100px">
										</li>
										<li class="fl">
											<p>${s.pname }</p>
											<p>颜色分类：${s.size }</p>
											<p>数量：${s.count }</p>
										</li>
										<li class="fr">￥${s.totalprice }</li>
									</ul>
					            </c:forEach>
					        </c:otherwise>
				        </c:choose>
					</div>
					<!--------tips---------------->
					<div class="tips">
						<p><span class="fl">商品金额：</span><span class="fr">￥${total }</span></p>
						<p><span class="fl">优惠金额：</span><span class="fr">￥0.00</span></p>
						<p><span class="fl">运费：</span><span class="fr">免运费</span></p>
					</div>
					<!--------tips count---------------->
					<div class="count tips">
						<p><span class="fl">合计：</span><span class="fr">￥${total }</span></p>
					</div>
					<!--<input type="button" name="" value="去支付"> -->
					<a href="javascript:createOrder();" class="pay">去支付</a>
					<input type="hidden" value="${ids }" id="ids">
				</div>
			</div>
		</div>
		<!--编辑弹框-->
		<!--遮罩-->
		<div class="mask"></div>
		<!--新增弹框-->
		<div class="adddz">
			<form action="#" method="post">
				<input type="text" name="name" id="name1" placeholder="姓名" class="on" />
				<input type="text" name="phone" id="phone1" placeholder="手机号" />
				<div class="city">
				
					<select id="s1" name="province"><option>省份</option></select>
					<select id="s2" name="city"><option>地级市</option></select>
					<select id="s3" name="area"><option>市、县级市、县</option></select>
	
				</div>
				<textarea name="addressInfo" rows="" id="addressInfo1" cols="" placeholder="详细地址"></textarea>
				<div class="bc">
					<input type="button" onclick="addAddress()" value="新增" />
					<input type="button" value="取消" />
				</div>
			</form>
		</div>
		
		<!--編輯弹框-->
		<div class="readd">
			<form action="#" method="get">
				<input type="text" name="name" id="name"  placeholder="姓名" class="on"/>
				<input type="text" name="phone" id="phone" placeholder="手机号" />
				<div class="city">
					
					<select id="s4" name="province"><option>省份</option></select>
					<select id="s5" name="city"><option>地级市</option></select>
					<select id="s6"name="area"><option>市、县级市、县</option></select>
					
				</div>
				<textarea name="addressInfo" id="addressInfo" rows="" cols="" placeholder="详细地址"></textarea>
				<div class="bc">
					<input type="button" onclick="editAddress()" value="修改" />
					<input type="hidden" value="" id="id" />
					<input type="button" onclick="editUpQx()" value="取消" />
				</div>
			</form>
		</div>
		<!--返回顶部-->
		<div class="gotop">
			<a href="cart.html">
			<dl>
				<dt><img src="images/gt1.png"/></dt>
				<dd>去购<br />物车</dd>
			</dl>
			</a>
			<a href="#" class="dh">
			<dl>
				<dt><img src="images/gt2.png"/></dt>
				<dd>联系<br />客服</dd>
			</dl>
			</a>
			<a href="mygxin.html">
			<dl>
				<dt><img src="images/gt3.png"/></dt>
				<dd>个人<br />中心</dd>
			</dl>
			</a>
			<a href="#" class="toptop" style="display: none;">
			<dl>
				<dt><img src="images/gt4.png"/></dt>
				<dd>返回<br />顶部</dd>
			</dl>
			</a>
			<p>400-800-8200</p>
		</div>
		<!--footer
		<div class="footer">
			<div class="top">
				<div class="wrapper">
					<div class="clearfix">
						<a href="#2" class="fl"><img src="img/foot1.png"/></a>
						<span class="fl">7天无理由退货</span>
					</div>
					<div class="clearfix">
						<a href="#2" class="fl"><img src="img/foot2.png"/></a>
						<span class="fl">15天免费换货</span>
					</div>
					<div class="clearfix">
						<a href="#2" class="fl"><img src="img/foot3.png"/></a>
						<span class="fl">满599包邮</span>
					</div>
					<div class="clearfix">
						<a href="#2" class="fl"><img src="img/foot4.png"/></a>
						<span class="fl">手机特色服务</span>
					</div>
				</div>
			</div>
			<p class="dibu">最家家居&copy;2013-2017公司版权所有 京ICP备080100-44备0000111000号<br />
			违法和不良信息举报电话：188-0130-1238，本网站所列数据，除特殊说明，所有数据均出自我司实验室测试</p>
		</div>-->
		<script src="js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/addressJL.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/public.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/pro.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/user.js" type="text/javascript" charset="utf-8"></script>
		
		<script type="text/javascript">
			function editUp(id,name,phone,addressInfo){
				setup2();
				$("#id").val(id);
				$("#name").val(name);
				$("#phone").val(phone);
				$("#addressInfo").val(addressInfo);
				$(".mask").show();
				$(".readd").show();
			}
			function editUpQx(){
				$(".mask").hide();
				$(".readd").hide();
			}
			function editAdd(){
				setup();
				$(".mask").show();
				$(".adddz").show();
			}
			function  editAddress(){	
				$.ajax({
					type: 'post',	 			//提交方式get或者post
					url: 'editAddress.do',					//提交url
					data: {
						"id":$("#id").val(),
						"province":$("#s4").val(),
						"city":$("#s5").val(),
						"area":$("#s6").val(),
						"name":$("#name").val(),
						"phone":$("#phone").val(),
						"addressInfo":$("#addressInfo").val()
						},					
					dataType: 'json',			//返回数据的格式
					success: function(rsl){	//成功返回之后的调用
						alert(rsl.msg);
						if(rsl.code == 0){
							location.reload();
						}
					},
					error: function(){
						alert("操作失败！！！")
					}
				});
			}
			function  addAddress(){	
				$.ajax({
					type: 'post',	 			//提交方式get或者post
					url: 'addAddress.do',					//提交url
					data: {
						"province":$("#s1").val(),
						"city":$("#s2").val(),
						"area":$("#s3").val(),
						"name":$("#name1").val(),
						"phone":$("#phone1").val(),
						"addressInfo":$("#addressInfo1").val()
						},					
					dataType: 'json',			//返回数据的格式
					success: function(rsl){	//成功返回之后的调用
						alert(rsl.msg);
						if(rsl.code == 0){
							location.reload();
						}
						
					},
					error: function(){
						alert("操作失败！！！")
					}
				});
			}
			function  deleteAddress(id){	
				$.ajax({
					type: 'post',	 			//提交方式get或者post
					url: 'deleteAddress.do',					//提交url
					data: {
						"id":id
						},					
					dataType: 'json',			//返回数据的格式
					success: function(rsl){	//成功返回之后的调用
						alert(rsl.msg);
						location.reload();
					},
					error: function(){
						alert("操作失败！！！")
					}
				});
			}
		
			function createOrder(){
				var addressId='';
				
				$("div[divFlag='address']").each(function(){
					var sc=$(this).hasClass("on");
					if(sc){
						addressId=$(this).attr("addressId");
					}
				});
				//var test="createOrder.do?ids="+$("#ids").val()+"&addressId="+addressId;
				//location.href="createOrder.do?ids="+$("#ids").val()+"&addressId="+addressId;
				$.ajax({
					type: 'post',
					url: 'createOrder.do',
					data:{"ids":$("#ids").val(),"addressId":addressId},
					dataType:'json',
					success:function(rsl){
						/*生成订单成功，跳到付款页面*/
						
						var orderid=rsl.data.orderid;
						var totalprices=rsl.data.totalprices;
						var userid=rsl.data.userid;
						
						location.href="toAlipayPage.do?WIDout_trade_no="+orderid+"&WIDtotal_amount="+totalprices+"&WIDsubject="+userid;
					},
					error:function(){
						alert("操作失败！！！")
					}
				});
			}
		</script>
	</body>
</html>
